/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-23
 * Time: 23:38
 */
public class Test {

    public static final long COUNT = 20_0000_0000;

    public static void seral(){

        long begin = System.currentTimeMillis();//记录开始时间
        int a= 0;

        for(long i =0;i<COUNT;++i){
            a++;
        }

        a =0 ;
        for(long i = 0;i<COUNT;++i){
            a++;
        }

        long end = System.currentTimeMillis();//记录结束时间

        System.out.println("单线程消耗时间" + (end - begin) + "ms");
    }


    public static void currency() {

        long begin = System.currentTimeMillis();//记录开始时间
        Thread t1 = new Thread(()->{
            int a= 0;
            for(long i =0;i<COUNT;++i){
                a++;
            }
        });

        Thread t2 = new Thread(()->{
            int a= 0;
            for(long i =0;i<COUNT;++i){
                a++;
            }
        });

        t1.start();//创建t1线程
        t2.start();//创建t2线程


        try {
            t1.join();//等待t1线程结束
            t2.join();//等待t2线程结束
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();//记录结束时间

        System.out.println("多线程消耗时间" + (end - begin) + "ms");

    }

    public static void main(String[] args) {

        //seral();
        currency();

    }

}
